package com.tsing.wms.controller;


import com.tsing.wms.service.IStorehouseService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.IdsReqVO;
import com.tsing.wms.vo.req.StoreReqVO;
import com.tsing.wms.vo.req.SupplierPageReqVO;
import com.tsing.wms.vo.resp.StoreRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "仓库管理")
@RestController
@RequestMapping("/storehouse")
public class StorehouseController {

    @Autowired
    private IStorehouseService storehouseService;

    @PostMapping("/addStore")
    @ApiOperation(value = "新增仓库")
    public ResultData addStore(@Validated({AddGroup.class}) @RequestBody StoreReqVO reqVO, HttpServletRequest request) {
        storehouseService.addStore(reqVO, request);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteStore")
    @ApiOperation(value = "删除仓库")
    public ResultData deleteStore(@Validated @RequestBody IdsReqVO reqVO, HttpServletRequest request) {
        storehouseService.deleteStore(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getStore")
    @ApiOperation(value = "查询仓库详情")
    public ResultData<StoreRespVO> getStore(@Validated IdReqVO reqVO) {
        return ResultUtil.success(storehouseService.getStore(reqVO));
    }

    @PutMapping("/updateStore")
    @ApiOperation(value = "修改仓库")
    public ResultData updateStore(@Validated({UpdateGroup.class}) @RequestBody StoreReqVO reqVO, HttpServletRequest request) {
        storehouseService.updateStore(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/storePage")
    @ApiOperation(value = "仓库分页")
    public ResultData<PageResultVO<StoreRespVO>> storePage(@Validated SupplierPageReqVO reqVO) {
        return ResultUtil.success(storehouseService.storePage(reqVO));
    }

}
